#include "ScnsDs18b20.c.h"

#if defined(SCNS_DS18B20_ENABLE)&&SCNS_DS18B20_ENABLE==1

#include "ScnsMenu.h"
#include "ScnsMath.h"

const uint8 scnsBspDs18b20Id[SCNS_DS18B20_MAX][8]={
    {0X28,0XB2,0X7C,0X3E,0X61,0X22,0X01,0X66,},
    //{0X28,0X9B,0XD0,0X87,0X61,0X22,0X01,0X56,},
    //{0X28,0XEE,0X73,0XB8,0X16,0X16,0X02,0XEB,},
};

//0X28,0X9B,0XD0,0X87,0X61,0X22,0X01,0X56,
ScnsStatus scnsBspDs18b20PostInit(ScnsDs18b20Enum ds1N)
{
    scnsMenuSetPage(4,"ds18b20",NULL);
    scnsMenuAddConstStruct(4,scnsDs18b20Result[ds1N],temperature,,SCNS_TYPE_FLOAT);
    return SCNS_STATUS_OK;
}

void scnsBspDs18b20SetDir(ScnsDs18b20Enum ds1N,uint8 in)
{
    const uint32 hb=scnsMathGetHighest1(ONE_WIRE_Pin)*2;
    ONE_WIRE_GPIO_Port->MODER&=~(3<<(hb));
    if(!in)
        ONE_WIRE_GPIO_Port->MODER|=1<<(hb);
}

void scnsBspDs18b20Set(ScnsDs18b20Enum ds1N,uint8 dat)
{
    ONE_WIRE_GPIO_Port->BSRR=(dat)?(ONE_WIRE_Pin):(ONE_WIRE_Pin<<16);
}

uint8 scnsBspDs18b20Get(ScnsDs18b20Enum ds1N)
{
    return (ONE_WIRE_GPIO_Port->IDR&ONE_WIRE_Pin)?1:0;
}

#endif
